-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Crane,,Name>
-- Create date: <2011/11/28,,>
-- Description:	<Pickup new order,,>
-- =============================================
CREATE PROCEDURE dbo.Pickup_Order
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @OrderId INT
	SELECT TOP 1 @OrderId = OrderID 
	FROM [dbo].[Order]
	WHERE [Status] = 'New'
	ORDER BY OrderID ASC 
	
	--PRINT  @OrderId 
	
	UPDATE [dbo].[Order]
	SET [Status] = 'Pending'
	WHERE OrderID = @OrderId 
    
	SELECT O.[OrderID], C.[CardNumber],
	P.[Amount],  P.PaymentId
	FROM [dbo].[Order] O
	JOIN dbo.Payment P ON O.OrderId =  P.OrderId
	JOIN dbo.CardInfo C ON P.AccountId = C.AccountId
	WHERE O.OrderID = @OrderId
END
GO
